package com.fsl.springbootdesignpattern.d_proxy.CustomProxy;

import java.lang.reflect.Method;

/**
 * 代理类
 */
public class HuangNiu implements MyInvocationHandler {

    private Object target;

    public HuangNiu(Object target) {
        this.target = target;
    }

    public <T> T getProxy(){
        return (T) MyProxy.newProxyInstance(new MyClassLoader(), target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy start");
        Object invoke = method.invoke(target, args);
        System.out.println("proxy end");
        return invoke;
    }
}
